﻿Imports System.Drawing.Drawing2D
Imports System.Drawing

Public Class gdButton
    Inherits System.Windows.Forms.Button
    Dim DownEvent As Boolean = False
    Dim Overg As Boolean = False
    Dim OnFocus As Boolean = False, onOver As Boolean = False
    ' Private mNormalColor1 As Color=
    Public Event UIChange(ByVal Image As Bitmap)
    Dim mAttatchSkin As Boolean = False, mTextByPath As Boolean = False
    Private Enum EnumMouseEvent
        MouseLeave = 0
        MouseMove = 1
        MouseDown = 2
    End Enum
    Private Enum buttonStyle
        ''' <summary>
        ''' 正常为选中按钮
        ''' </summary>
        ButtonNormal
        ''' <summary>
        ''' 获得焦点的按钮
        ''' </summary>
        ButtonFocuse
        ''' <summary>
        ''' 鼠标经过样式
        ''' </summary>
        ButtonMouseOver
        ''' <summary>
        ''' 获得焦点并鼠标经过
        ''' </summary>
        ButtonFocuseAndMouseOver
        ''' <summary>
        ''' 鼠标按下事件
        ''' </summary>
        ButtonMouseDown
    End Enum
    Private mR As Integer = 3
    'Public mNormalColor1 As Color = Color.FromArgb(255, 248, 214, 151)
    'Public mNormalColor2 As Color = Color.FromArgb(255, 242, 197, 107)
    'Public mNormalColor3 As Color = Color.FromArgb(255, 242, 197, 107)
    'Public mNormalColor4 As Color = Color.FromArgb(255, 248, 214, 151)
    Private mNormalColor As Color() = New Color() {Color.FromArgb(255, 248, 214, 151), Color.FromArgb(255, 242, 197, 107), Color.FromArgb(255, 242, 197, 107), Color.FromArgb(255, 248, 214, 151)}
    Public mNormalBorder As Color = Color.FromArgb(255, 242, 149, 54)
    'Public mFocusColor1 As Color = Color.FromArgb(255, 255, 252, 216)
    'Public mFocusColor2 As Color = Color.FromArgb(255, 255, 235, 161)
    'Public mFocusColor3 As Color = Color.FromArgb(255, 255, 213, 74)
    'Public mFocusColor4 As Color = Color.FromArgb(255, 255, 234, 171)
    Private mFocusColor As Color() = New Color() {Color.FromArgb(255, 242, 149, 54), Color.FromArgb(255, 255, 252, 216), Color.FromArgb(255, 255, 235, 161), Color.FromArgb(255, 255, 213, 74), Color.FromArgb(255, 255, 234, 171)}
    'Public mDownColor1 As Color = Color.FromArgb(255, 245, 202, 154)
    'Public mDownColor2 As Color = Color.FromArgb(255, 251, 177, 106)
    'Public mDownColor3 As Color = Color.FromArgb(255, 249, 154, 54)
    'Public mDownColor4 As Color = Color.FromArgb(255, 253, 240, 175)
    Private mDownColor As Color() = New Color() {Color.FromArgb(255, 245, 202, 154), Color.FromArgb(255, 251, 177, 106), Color.FromArgb(255, 249, 154, 54), Color.FromArgb(255, 253, 240, 175)}
    Public mDownBorder As Color = Color.FromArgb(255, 142, 129, 101)
    Public mFocusBorder As Color = Color.FromArgb(255, 192, 167, 118)
    Public mTextColor1 As Color = Color.FromArgb(255, 120, 156, 35)
    Public mTextColor2 As Color = Color.FromArgb(255, 51, 74, 33)
    Public mTextBorderColor As Color = Color.FromArgb(200, 235, 231, 224)
#Region "自定义属性"
    Public Property Radius() As Integer
        Get
            Return mR
        End Get
        Set(ByVal value As Integer)
            If mR > 0 Then mR = value : Me.Refresh()
        End Set
    End Property
    Public Property TextColor1() As Color
        Get
            Return mTextColor1
        End Get
        Set(ByVal value As Color)
            mTextColor1 = value
            Me.Refresh()
        End Set
    End Property
    Public Property TextColor2() As Color
        Get
            Return mTextColor2
        End Get
        Set(ByVal value As Color)
            mTextColor2 = value
            Me.Refresh()
        End Set
    End Property
    Public Property TextBorderColor() As Color
        Get
            Return mTextBorderColor
        End Get
        Set(ByVal value As Color)
            mTextBorderColor = value
            Me.Refresh()
        End Set
    End Property
    Public Property DownColor() As Color()
        Get
            Return mDownColor
        End Get
        Set(ByVal value As Color())
            mDownColor = value
            Me.Refresh()
        End Set
    End Property
    Public Property DownBorder() As Color
        Get
            Return mDownBorder
        End Get
        Set(ByVal value As Color)
            mDownBorder = value
            Me.Refresh()
        End Set
    End Property
    Public Property FocusBorder() As Color
        Get
            Return mFocusBorder
        End Get
        Set(ByVal value As Color)
            mFocusBorder = value
            Me.Refresh()
        End Set
    End Property
    Public Property FocusColor() As Color()
        Get
            Return mFocusColor
        End Get
        Set(ByVal value As Color())
            mFocusColor = value
            Me.Refresh()
        End Set
    End Property
    Public Property NormalBorder() As Color
        Get
            Return mNormalBorder
        End Get
        Set(ByVal value As Color)
            mNormalBorder = value
            Me.Refresh()
        End Set
    End Property
    'Public Property NormalColor4() As Color
    '    Get
    '        Return mNormalColor4
    '    End Get
    '    Set(ByVal value As Color)
    '        mNormalColor4 = value
    '        Me.Refresh()
    '    End Set
    'End Property
    'Public Property NormalColor3() As Color
    '    Get
    '        Return mNormalColor3
    '    End Get
    '    Set(ByVal value As Color)
    '        mNormalColor3 = value
    '        Me.Refresh()
    '    End Set
    'End Property
    'Public Property NormalColor2() As Color
    '    Get
    '        Return mNormalColor2
    '    End Get
    '    Set(ByVal value As Color)
    '        mNormalColor2 = value
    '        Me.Refresh()
    '    End Set
    'End Property
    Public Property NormalColor() As Color()
        Get
            Return mNormalColor
        End Get
        Set(ByVal value As Color())
            mNormalColor = value
            Me.Refresh()
        End Set
    End Property
    Public Property AttachSkin() As Boolean
        Get
            Return mAttatchSkin
        End Get
        Set(ByVal value As Boolean)
            mAttatchSkin = value
            Me.Refresh()
        End Set
    End Property
    ''' <summary>
    ''' 是否使用画刷绘制渐变文字
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property DrawTextByPath() As Boolean
        Get
            Return mTextByPath
        End Get
        Set(ByVal value As Boolean)
            mTextByPath = value
            Me.Refresh()
        End Set
    End Property
#End Region
    Protected Overrides Sub OnPaint(ByVal pevent As System.Windows.Forms.PaintEventArgs)
        If mAttatchSkin = True Then
            Dim g As Graphics = pevent.Graphics

            Dim Bounds As Rectangle = New Rectangle(0, 0, Me.Width - 1, Me.Height - 1)
            If Bounds.Width <= 0 Or Bounds.Height <= 0 Then Return
            g.SmoothingMode = SmoothingMode.HighQuality
            ' g.Clear(Me.BackColor)
            Try
                If onOver = True And DownEvent = False And OnFocus = False Then
                    DrawButton(g, Bounds, buttonStyle.ButtonMouseOver)
                ElseIf onOver = True And DownEvent = False And OnFocus = True Then
                    DrawButton(g, Bounds, buttonStyle.ButtonFocuseAndMouseOver)
                ElseIf onOver = True And DownEvent = True Then
                    DrawButton(g, Bounds, buttonStyle.ButtonMouseDown)
                ElseIf onOver = False And DownEvent = False And OnFocus = False Then
                    DrawButton(g, Bounds, buttonStyle.ButtonNormal)
                ElseIf onOver = False And DownEvent = False And OnFocus = True Then
                    DrawButton(g, Bounds, buttonStyle.ButtonNormal)
                ElseIf onOver = True And DownEvent = False And OnFocus = True Then
                    DrawButton(g, Bounds, buttonStyle.ButtonFocuseAndMouseOver)
                End If

            Catch ex As Exception
                'MsgBox(ex.Message)
            End Try

            Return
        End If
        MyBase.OnPaint(pevent)
    End Sub

    Private Sub gdButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click

    End Sub

    Private Sub gdButton_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.GotFocus
        OnFocus = True
    End Sub

    Private Sub gdButton_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LostFocus
        OnFocus = False
    End Sub

    Private Sub gdButton_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        DownEvent = True
        Overg = False
    End Sub

    Private Sub gdButton_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
        DownEvent = False
        Overg = False
        onOver = False
    End Sub

    Private Sub gdButton_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        onOver = True
        Overg = True
    End Sub

    Private Sub gdButton_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
        DownEvent = False
        Overg = False
        If mAttatchSkin = False Then Exit Sub
        Me.Refresh()
    End Sub

    Private Sub gdButton_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        If Me.Width > 0 And Me.Height > 0 Then
            Dim Bounds As Rectangle = New Rectangle(0, 0, Me.Width, Me.Height)
            Dim sPath As GraphicsPath = CreateRoundPath(Bounds, mR)
            Me.Region = New Region(sPath)
            sPath.Dispose()
        End If
    End Sub
    Private Sub DrawButton(ByVal g As Graphics, ByVal Bounds As Rectangle, ByVal BtnStyle As buttonStyle)
        '   Me.Parent.Text += "1"
        If Bounds.Width <= 0 Or Bounds.Height <= 0 Then Exit Sub
        g.SmoothingMode = SmoothingMode.HighQuality
        Dim TopRect As Rectangle, BottomRect As Rectangle, mBorderColor As Color
        TopRect = New Rectangle(Bounds.Location, New Size(Bounds.Width, Bounds.Height / 2))
        BottomRect = New Rectangle(Bounds.Left, Bounds.Top + Bounds.Height / 2 - 1, Bounds.Width, Bounds.Height / 2 + 1)
        g.FillRectangle(New SolidBrush(Me.BackColor), New Rectangle(0, 0, Me.Width, Me.Width))
        '==============设置画刷颜色
        Dim BrushColor As Color() = Nothing  ', BrushColor2 As Color, BrushColor3 As Color, BrushColor4 As Color
        If BtnStyle = buttonStyle.ButtonFocuse Or BtnStyle = buttonStyle.ButtonNormal Then
            ' BrushColor1 = mNormalColor1 : BrushColor2 = mNormalColor2 : BrushColor3 = mNormalColor3 : BrushColor4 = mNormalColor4
            BrushColor = mNormalColor
            mBorderColor = mNormalBorder
        ElseIf BtnStyle = buttonStyle.ButtonMouseOver Then
            BrushColor = mFocusColor
            mBorderColor = mFocusBorder
        ElseIf BtnStyle = buttonStyle.ButtonFocuseAndMouseOver Then
            BrushColor = mFocusColor
            mBorderColor = mFocusBorder
        ElseIf BtnStyle = buttonStyle.ButtonMouseDown Then
            BrushColor = mDownColor
            mBorderColor = mDownBorder
        End If
        '==============设置画刷颜色
        '====================================绘制背景
        'Dim TopBrush As New LinearGradientBrush(TopRect, BrushColor1, BrushColor2, LinearGradientMode.Vertical)
        'Dim BottomBrush As New LinearGradientBrush(BottomRect, BrushColor3, BrushColor4, LinearGradientMode.Vertical)
        Dim BorderPath As GraphicsPath = CreateRoundPath(Bounds, mR)
        Dim DrawBrush As New LinearGradientBrush(Bounds, BrushColor(0), BrushColor(1), LinearGradientMode.Vertical)
        Dim ColorBlends As ColorBlend
        ColorBlends = getColorBlendByColors(BrushColor)
        DrawBrush.InterpolationColors = ColorBlends
        ' g.FillPath(TopBrush, TopPath)
        ' g.FillPath(BottomBrush, BottomPath)
        g.FillPath(DrawBrush, BorderPath)
        '====================================绘制背景
        Dim Effect As Integer = 4
        Dim FocusRect As Rectangle = New Rectangle(Bounds.Left + Effect, Bounds.Top + Effect, Bounds.Width - Effect * 2, Bounds.Height - 2 * Effect)
        g.DrawPath(New Pen(mBorderColor, 1), BorderPath)
        If OnFocus Then '==========绘制焦点虚线
            Dim FocusPath As GraphicsPath = CreateRoundPath(FocusRect, mR)
            Dim p As New Pen(mBorderColor, 0.5F)
            p.DashStyle = DashStyle.Dash
            g.DrawPath(p, FocusPath)
            FocusPath.Dispose()
        End If
        '==================================如有需显示背景图片显示图片
        If Not Me.Image Is Nothing Then
            Select Case Me.ImageAlign
                Case ContentAlignment.TopLeft
                    g.DrawImage(Me.Image, FocusRect, New Rectangle(0, 0, FocusRect.Width, FocusRect.Height), GraphicsUnit.Pixel)
                Case ContentAlignment.TopCenter
                    g.DrawImage(Me.Image, New Rectangle((Bounds.Width - Me.Image.Width) / 2, FocusRect.Top, Me.Image.Width, Me.Image.Height), New Rectangle(0, 0, Me.Image.Width, Me.Image.Height), GraphicsUnit.Pixel)
                Case ContentAlignment.TopRight
                    ' Me.Parent.Text = "topright"
                    g.DrawImage(Me.Image, New Rectangle(FocusRect.Right - Me.Image.Width, FocusRect.Top, Me.Image.Width, Me.Image.Height), New Rectangle(0, 0, Me.Image.Width, Me.Image.Width), GraphicsUnit.Pixel)
                Case ContentAlignment.MiddleLeft
                    If Me.Image.Width <= FocusRect.Width And Me.Image.Height <= FocusRect.Height Then
                        g.DrawImage(Me.Image, FocusRect.Left, Convert.ToInt32((Bounds.Height - Me.Image.Height) / 2), Me.Image.Width, Me.Image.Height)
                    Else
                        g.DrawImage(Me.Image, New Rectangle(FocusRect.Left, FocusRect.Top, FocusRect.Width, FocusRect.Height), New Rectangle(0, FocusRect.Top - Convert.ToInt32((Bounds.Height - Me.Image.Height) / 2), FocusRect.Width, FocusRect.Height), GraphicsUnit.Pixel)
                    End If
                Case ContentAlignment.MiddleRight
                    If Me.Image.Width <= FocusRect.Width And Me.Image.Height <= FocusRect.Height Then
                        g.DrawImage(Me.Image, FocusRect.Right - Me.Image.Width, Convert.ToInt32((FocusRect.Height - Me.Image.Height) / 2), Me.Image.Width, Me.Image.Height)
                    Else
                        g.DrawImage(Me.Image, FocusRect, New Rectangle(Me.Image.Width - FocusRect.Width, FocusRect.Top - Convert.ToInt32((Bounds.Height - Me.Image.Height) / 2), FocusRect.Width, FocusRect.Height), GraphicsUnit.Pixel)
                    End If
                Case ContentAlignment.MiddleCenter
                    If Me.Image.Width <= FocusRect.Width And Me.Image.Height <= FocusRect.Height Then
                        g.DrawImage(Me.Image, Convert.ToInt32((FocusRect.Left + (FocusRect.Width - Me.Image.Width) / 2)), FocusRect.Top + Convert.ToInt32((FocusRect.Height - Me.Image.Height) / 2), Me.Image.Width, Me.Image.Height)
                    Else
                        g.DrawImage(Me.Image, FocusRect, FocusRect, GraphicsUnit.Pixel)
                    End If
                Case ContentAlignment.BottomLeft
                    If Me.Image.Width <= FocusRect.Width And Me.Image.Height <= FocusRect.Height Then
                        g.DrawImage(Me.Image, FocusRect.Left, FocusRect.Bottom - Me.Image.Height, Me.Image.Width, Me.Image.Height)
                    Else
                        g.DrawImage(Me.Image, FocusRect, New Rectangle(0, Me.Image.Height - FocusRect.Height, FocusRect.Width, FocusRect.Height), GraphicsUnit.Pixel)
                    End If
                Case ContentAlignment.BottomCenter
                    If Me.Image.Width <= FocusRect.Width And Me.Image.Height <= FocusRect.Height Then
                        g.DrawImage(Me.Image, Convert.ToInt32(FocusRect.Left + (FocusRect.Width - Me.Image.Width) / 2), FocusRect.Bottom - Me.Image.Height, Me.Image.Width, Me.Image.Height)
                    Else
                        g.DrawImage(Me.Image, New Rectangle(Convert.ToInt32(FocusRect.Left + (FocusRect.Width - Me.Image.Width) / 2), FocusRect.Bottom - Me.Image.Height, Me.Image.Width, Me.Image.Height), New Rectangle(Convert.ToInt32(FocusRect.Left + (FocusRect.Width - Me.Image.Width) / 2), FocusRect.Bottom - Me.Image.Height, Me.Image.Width, Me.Image.Height), GraphicsUnit.Pixel)

                    End If
                Case ContentAlignment.BottomRight
                    If Me.Image.Width <= FocusRect.Width And Me.Image.Height <= FocusRect.Height Then
                        g.DrawImage(Me.Image, FocusRect.Right - Me.Image.Width, FocusRect.Bottom - Me.Image.Height, Me.Image.Width, Me.Image.Height)
                    Else
                        g.DrawImage(Me.Image, FocusRect, New Rectangle(Me.Image.Width - FocusRect.Width, Me.Image.Height - FocusRect.Height, FocusRect.Width, FocusRect.Height), GraphicsUnit.Pixel)
                    End If
            End Select
        End If
        '==================================如有需显示背景图片显示图片
        '==================================绘制文本
        Dim TextPath As GraphicsPath = New GraphicsPath(FillMode.Alternate)
        Dim TextBrush As New SolidBrush(Me.ForeColor), strFormat As StringFormat
        Dim TextFont As New Font(Me.Font.Name, Me.Font.Size, FontStyle.Regular)
        strFormat = New StringFormat
        If Me.Enabled = False Then TextBrush = New SolidBrush(Color.FromArgb(150, 150, 150))
        Select Case TextAlign
            Case ContentAlignment.TopLeft
                If mTextByPath Then
                    strFormat.LineAlignment = StringAlignment.Near
                    strFormat.Alignment = StringAlignment.Near
                    TextPath.AddString(Me.Text, New FontFamily(Me.Font.Name), Me.Font.Style, Me.Font.Size, FocusRect, strFormat)
                    Dim Tsize As SizeF = g.MeasureString(Me.Text, TextFont)
                    Dim DrawRect As Rectangle = New Rectangle(FocusRect.Location, Tsize.ToSize)
                    Dim TBrush As New LinearGradientBrush(DrawRect, mTextColor1, mTextColor2, LinearGradientMode.Vertical)
                    g.FillPath(TBrush, TextPath)
                    g.DrawPath(New Pen(mTextBorderColor, 0.5F), TextPath)
                Else
                    strFormat.LineAlignment = StringAlignment.Near
                    strFormat.Alignment = StringAlignment.Near
                    g.DrawString(Me.Text, TextFont, TextBrush, FocusRect, strFormat)
                End If
            Case ContentAlignment.TopCenter
                If mTextByPath Then
                    strFormat.LineAlignment = StringAlignment.Near
                    strFormat.Alignment = StringAlignment.Center
                    TextPath.AddString(Me.Text, New FontFamily(Me.Font.Name), Me.Font.Style, Me.Font.Size, FocusRect, strFormat)
                    Dim Tsize As SizeF = g.MeasureString(Me.Text, TextFont)
                    Dim DrawRect As Rectangle = New Rectangle(FocusRect.Location, Tsize.ToSize)
                    Dim TBrush As New LinearGradientBrush(DrawRect, mTextColor1, mTextColor2, LinearGradientMode.Vertical)
                    g.FillPath(TBrush, TextPath)
                    g.DrawPath(New Pen(mTextBorderColor, 0.5F), TextPath)
                Else
                    strFormat.LineAlignment = StringAlignment.Near
                    strFormat.Alignment = StringAlignment.Center
                    g.DrawString(Me.Text, TextFont, TextBrush, FocusRect, strFormat)
                End If
            Case ContentAlignment.TopRight
                If mTextByPath Then
                    strFormat.LineAlignment = StringAlignment.Near
                    strFormat.Alignment = StringAlignment.Far
                    TextPath.AddString(Me.Text, New FontFamily(Me.Font.Name), Me.Font.Style, Me.Font.Size, FocusRect, strFormat)
                    Dim Tsize As SizeF = g.MeasureString(Me.Text, TextFont)
                    Dim DrawRect As Rectangle = New Rectangle(FocusRect.Right - Tsize.Width, FocusRect.Top, Tsize.Width, Tsize.Height)
                    Dim TBrush As New LinearGradientBrush(DrawRect, mTextColor1, mTextColor2, LinearGradientMode.Vertical)
                    g.FillPath(TBrush, TextPath)
                    g.DrawPath(New Pen(mTextBorderColor, 0.5F), TextPath)
                Else
                    strFormat.LineAlignment = StringAlignment.Near
                    strFormat.Alignment = StringAlignment.Far
                    g.DrawString(Me.Text, TextFont, TextBrush, FocusRect, strFormat)
                End If
            Case ContentAlignment.MiddleLeft
                If mTextByPath Then
                    strFormat.LineAlignment = StringAlignment.Center
                    strFormat.Alignment = StringAlignment.Near
                    TextPath.AddString(Me.Text, New FontFamily(TextFont.Name), TextFont.Style, TextFont.Size, FocusRect, strFormat)
                    Dim Tsize As SizeF = g.MeasureString(Me.Text, TextFont)
                    Dim DrawRect As Rectangle = New Rectangle(FocusRect.Left, FocusRect.Top + Convert.ToInt32((FocusRect.Height - Tsize.Height) / 2), Tsize.Width, Tsize.Height)
                    Dim TBrush As New LinearGradientBrush(DrawRect, mTextColor1, mTextColor2, LinearGradientMode.Vertical)
                    g.FillPath(TBrush, TextPath)
                    g.DrawPath(New Pen(mTextBorderColor, 0.5F), TextPath)
                Else
                    strFormat.LineAlignment = StringAlignment.Center
                    strFormat.Alignment = StringAlignment.Near
                    g.DrawString(Me.Text, TextFont, TextBrush, FocusRect, strFormat)
                End If
            Case ContentAlignment.MiddleCenter
                If mTextByPath Then
                    strFormat.LineAlignment = StringAlignment.Center
                    strFormat.Alignment = StringAlignment.Center
                    TextPath.AddString(Me.Text, New FontFamily(TextFont.Name), TextFont.Style, TextFont.Size, FocusRect, strFormat)
                    Dim Tsize As SizeF = g.MeasureString(Me.Text, TextFont)
                    Dim DrawRect As Rectangle = New Rectangle(FocusRect.Left + Convert.ToInt32((FocusRect.Width - Tsize.Width) / 2), FocusRect.Top + Convert.ToInt32((FocusRect.Height - Tsize.Height) / 2), Tsize.Width, Tsize.Height)
                    Dim TBrush As New LinearGradientBrush(DrawRect, mTextColor1, mTextColor2, LinearGradientMode.Vertical)
                    g.FillPath(TBrush, TextPath)
                    g.DrawPath(New Pen(mTextBorderColor, 0.5F), TextPath)
                Else
                    Try
                        strFormat.LineAlignment = StringAlignment.Center
                        strFormat.Alignment = StringAlignment.Center
                        g.DrawString(Me.Text, TextFont, TextBrush, FocusRect, strFormat)
                    Catch
                        Me.Parent.Text = Me.Text & "|" & TextFont.Name & "|" & TextBrush.ToString & "|" & FocusRect.Width
                        If TextFont Is Nothing Then Me.Parent.Text = "textbrush disposed"
                    End Try
                End If
            Case ContentAlignment.MiddleRight
                If mTextByPath Then
                    strFormat.LineAlignment = StringAlignment.Center
                    strFormat.Alignment = StringAlignment.Far
                    TextPath.AddString(Me.Text, New FontFamily(TextFont.Name), TextFont.Style, TextFont.Size, FocusRect, strFormat)
                    Dim Tsize As SizeF = g.MeasureString(Me.Text, TextFont)
                    Dim DrawRect As Rectangle = New Rectangle(FocusRect.Right - Tsize.Width, FocusRect.Top + Convert.ToInt32((FocusRect.Height - Tsize.Height) / 2), Tsize.Width, Tsize.Height)
                    Dim TBrush As New LinearGradientBrush(DrawRect, mTextColor1, mTextColor2, LinearGradientMode.Vertical)
                    g.FillPath(TBrush, TextPath)
                    g.DrawPath(New Pen(mTextBorderColor, 0.5F), TextPath)
                Else
                    strFormat.LineAlignment = StringAlignment.Center
                    strFormat.Alignment = StringAlignment.Far
                    g.DrawString(Me.Text, TextFont, TextBrush, FocusRect, strFormat)
                End If
            Case ContentAlignment.BottomLeft
                If mTextByPath Then
                    strFormat.LineAlignment = StringAlignment.Far
                    strFormat.Alignment = StringAlignment.Near
                    TextPath.AddString(Me.Text, New FontFamily(TextFont.Name), TextFont.Style, TextFont.Size, FocusRect, strFormat)
                    Dim Tsize As SizeF = g.MeasureString(Me.Text, TextFont)
                    Dim DrawRect As Rectangle = New Rectangle(FocusRect.Left, FocusRect.Bottom - Tsize.Height, Tsize.Width, Tsize.Height)
                    Dim TBrush As New LinearGradientBrush(DrawRect, mTextColor1, mTextColor2, LinearGradientMode.Vertical)
                    g.FillPath(TBrush, TextPath)
                    g.DrawPath(New Pen(mTextBorderColor, 0.5F), TextPath)
                Else
                    strFormat.LineAlignment = StringAlignment.Far
                    strFormat.Alignment = StringAlignment.Near
                    g.DrawString(Me.Text, TextFont, TextBrush, FocusRect, strFormat)
                End If
            Case ContentAlignment.BottomCenter
                If mTextByPath Then
                    strFormat.LineAlignment = StringAlignment.Far
                    strFormat.Alignment = StringAlignment.Center
                    TextPath.AddString(Me.Text, New FontFamily(TextFont.Name), TextFont.Style, TextFont.Size, FocusRect, strFormat)
                    Dim Tsize As SizeF = g.MeasureString(Me.Text, TextFont)
                    Dim DrawRect As Rectangle = New Rectangle(Convert.ToInt32((FocusRect.Width - Tsize.Width) / 2) + FocusRect.Left, FocusRect.Bottom - Tsize.Height, Tsize.Width, Tsize.Height)
                    Dim TBrush As New LinearGradientBrush(DrawRect, mTextColor1, mTextColor2, LinearGradientMode.Vertical)
                    g.FillPath(TBrush, TextPath)
                    g.DrawPath(New Pen(mTextBorderColor, 0.5F), TextPath)
                Else
                    strFormat.LineAlignment = StringAlignment.Far
                    strFormat.Alignment = StringAlignment.Center
                    g.DrawString(Me.Text, TextFont, TextBrush, FocusRect, strFormat)
                End If
            Case ContentAlignment.BottomRight
                If mTextByPath Then
                    strFormat.LineAlignment = StringAlignment.Far
                    strFormat.Alignment = StringAlignment.Far
                    TextPath.AddString(Me.Text, New FontFamily(TextFont.Name), TextFont.Style, TextFont.Size, FocusRect, strFormat)
                    Dim Tsize As SizeF = g.MeasureString(Me.Text, TextFont)
                    Dim DrawRect As Rectangle = New Rectangle(FocusRect.Right - Tsize.Width, FocusRect.Bottom - Tsize.Height, Tsize.Width, Tsize.Height)
                    Dim TBrush As New LinearGradientBrush(DrawRect, mTextColor1, mTextColor2, LinearGradientMode.Vertical)
                    g.FillPath(TBrush, TextPath)
                    g.DrawPath(New Pen(mTextBorderColor, 0.5F), TextPath)
                Else
                    strFormat.LineAlignment = StringAlignment.Far
                    strFormat.Alignment = StringAlignment.Far
                    g.DrawString(Me.Text, TextFont, TextBrush, FocusRect, strFormat)
                End If
        End Select
        strFormat.Dispose()
        TextPath.Dispose()
        '==================================绘制文本
        'TopPath.Dispose()
        'BottomPath.Dispose()
        BorderPath.Dispose()
        'TopBrush.Dispose()
        'BottomBrush.Dispose()

        RaiseEvent UIChange(Nothing)
    End Sub
    Public Function CreateRoundPath(ByVal Rect As Rectangle, ByVal R As Integer)
        Dim ResultPath As GraphicsPath = New GraphicsPath(FillMode.Alternate)
        Dim L As Integer = 2 * R
        Dim TmpRect As Rectangle = New Rectangle(Rect.Location, New Size(L, L))
        With ResultPath
            .AddArc(TmpRect, 180.0F, 90.0F)
            .AddLine(New Point(Rect.Left + R, Rect.Top), New Point(Rect.Right - R, Rect.Top))
            TmpRect.X = Rect.Right - L
            .AddArc(TmpRect, 270.0F, 90.0F)
            .AddLine(New Point(Rect.Right, Rect.Top + R), New Point(Rect.Right, Rect.Bottom - R))
            TmpRect.Y = Rect.Bottom - L
            .AddArc(TmpRect, 0.0F, 90.0F)
            .AddLine(New Point(Rect.Right - R, Rect.Bottom), New Point(Rect.Left + R, Rect.Bottom))
            TmpRect.X = Rect.Left
            .AddArc(TmpRect, 90.0F, 90.0F)
            .AddLine(New Point(Rect.Left, Rect.Bottom - R), New Point(Rect.Left, Rect.Top + R))
            Return ResultPath
        End With
    End Function
End Class

